﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Minecraft.Data.NBT;

namespace Minecraft.Data {
    public class Player : Mob {

        public int Score;
        public List<InventoryItem> Inventory;

        public Player() : base() {
            Inventory = new List<InventoryItem>();
        }
        public Player(Tag data)
            : base(data) {

            Inventory = new List<InventoryItem>();

            foreach (var child in data.Children) {
                switch (child.Name) {

                    case "Inventory":
                        foreach (var item in child.Children)
                            this.Inventory.Add(new InventoryItem(item));
                        break;

                    case "Score":
                        this.Score = (int)child.Payload;
                        break;

                    default:
                        break;
                }
            }
        }

        new public Tag ToTag() {

            Tag root = base.ToTag();
            root.Name = "Player";

            Tag inv = new Tag() { Type = TagType.List, Name = "Inventory", ListType = TagType.Compound };
            foreach (var item in Inventory)
                inv.Children.Add(item.ToTag());

            root.Children.Add(inv);
            root.Children.Add(new Tag() { Type = TagType.Int, Name = "Score", Payload = Score });
            return root;
        }
    }
}
